package com.itboye.eweilisten.me.timu.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.Html;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

import com.itboye.eweilisten.R;
import com.itboye.eweilisten.app.MyApplication;
import com.itboye.eweilisten.model.TIbean;
import com.itboye.eweilisten.model.TIbeanTwo;
import com.itboye.eweilisten.util.sputil.Const;
import com.itboye.eweilisten.util.widget.AutoResizeTextView;
import com.itboye.eweilisten.util.widget.AutoResizeTwoTextView;
import com.itboye.eweilisten.util.widget.FlowLayout;
import com.itboye.eweilisten.util.widget.LineEditText;
import com.itboye.eweilisten.util.widget.MyLinearLayout;
import com.itboye.eweilisten.util.widget.XImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * 综合类题型
 */
public class ZongHeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private LayoutInflater mLayoutInflater;
    private Context context;
    List<TIbeanTwo> list;
    private int totalEdit;
    int positionbbb = -1;
    private AlphaAnimation mAnimation1;

    Boolean firstRow = true;
    static Boolean upperCase;//首字母是否大写标志

    WanXingTwoAdapter wanxingAdapter;//完形填空
    List<TIbean.Clild> listWanXing;//完形填空用到
    int posBiao;//记录表格选好的数据的下标(6231)
    int posting;//记录听写选好的数据的下标（6229）（6233）
    int posxuan;//记录选词填空选好的数据的下标（6202）
    int posqing;//记录情景对话选好的数据的下标（6232）
    boolean isAnswer2;//判斷
    boolean isQuestion2;
    //建立枚举 item 类型
    public enum ITEM_TYPE {
        XUANCI,//选词填空（6202）
        BIAOGE,//表格(6231)
        DANXUAN,//单选(6226)
        PANDUAN_IMG,//图片判断(6228)
        DANCI_PX,//单词拼写（6233）  单词听写（6229）
        PANDUAN_YJ,//语句判断（6230）
        DUIHUA,//情景对话（6232）
        XUANZE_IMG,//图片选择（6203）
        WANXING,//完形填空（6227）
        ITEM2
    }

    public ZongHeAdapter(Context mContext, List<TIbeanTwo> list) {
        this.context = mContext;
        this.list = list;
        mLayoutInflater = LayoutInflater.from(context);
        listWanXing = new ArrayList<>();
        mAnimation1= new AlphaAnimation(1,0);
        mAnimation1.setRepeatCount(Animation.INFINITE);
        mAnimation1.setRepeatMode(Animation.REVERSE);
        mAnimation1.setDuration(1000);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //加载Item View的时候根据不同TYPE加载不同的布局
        if (viewType == ITEM_TYPE.XUANCI.ordinal()) {
            return new TiHolder.XuanCiHolder(mLayoutInflater.inflate(R.layout.eweitingtext, parent, false));

        } else if (viewType == ITEM_TYPE.BIAOGE.ordinal()) {
            return new TiHolder.BiaoGeHolder(mLayoutInflater.inflate(R.layout.item_biaogge, parent, false));

        } else if (viewType == ITEM_TYPE.DANXUAN.ordinal()) {
            return new TiHolder.DanXuanHolder(mLayoutInflater.inflate(R.layout.item_danxuans, parent, false));

        } else if (viewType == ITEM_TYPE.PANDUAN_IMG.ordinal()) {
            return new TiHolder.PanDuanIMGHolder(mLayoutInflater.inflate(R.layout.item_danxuan_img, parent, false));

        } else if (viewType == ITEM_TYPE.DANCI_PX.ordinal()) {
            return new TiHolder.DanCiPXHolder(mLayoutInflater.inflate(R.layout.eweitingtext, parent, false));

        } else if (viewType == ITEM_TYPE.PANDUAN_YJ.ordinal()) {
            return new TiHolder.PanDuanYJHolder(mLayoutInflater.inflate(R.layout.item_danxuan_yujv, parent, false));

        } else if (viewType == ITEM_TYPE.DUIHUA.ordinal()) {
            return new TiHolder.DuiHuaHolder(mLayoutInflater.inflate(R.layout.item_duihua, parent, false));

        } else if (viewType == ITEM_TYPE.XUANZE_IMG.ordinal()) {
            return new TiHolder.XuanZeIMGHolder(mLayoutInflater.inflate(R.layout.zuo_ti_a_two, parent, false));

        } else if (viewType == ITEM_TYPE.WANXING.ordinal()) {
            return new TiHolder.WanXingHolder(mLayoutInflater.inflate(R.layout.item_wanxing, parent, false));

        } else {
            return new Item1ViewHolder(mLayoutInflater.inflate(R.layout.item_goods_che, parent, false));
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        if (holder instanceof TiHolder.XuanCiHolder) {     //( 6202类型    仿写，单词拼写，选词填空等)
            Log.d("==================","xuanciholder");
            ((TiHolder.XuanCiHolder) holder).timu_num.setText(position + 1 + "");
            (((TiHolder.XuanCiHolder) holder).questionLine).removeAllViews();
            (((TiHolder.XuanCiHolder) holder).answerLine).removeAllViews();
            posxuan = 0;
            isAnswer2=true;
            isQuestion2=true;
            if(list.size()<=1){
                ((TiHolder.XuanCiHolder) holder).timu_num.setVisibility(View.GONE);
            }
            for (int j = 0; j < list.get(position).getContent().size(); j++) {
                wanXingContentAdd((((TiHolder.XuanCiHolder) holder).questionLine), list.get(position).getContent(), list.get(position).getAnwser_xuan(), (((TiHolder.XuanCiHolder) holder).answerLine), j, position);
            }

            for (int j = 0; j < (((TiHolder.XuanCiHolder) holder).questionLine).getChildCount(); j++) {
                if ("null".equals((((TiHolder.XuanCiHolder) holder).questionLine).getChildAt(j).getTag(R.id.selected) + "")) {

                } else {

                    // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                    if (list.get(position).getAnwser_xuan() == null) {//当选中的数据中没有数据的时候,
                        (((TiHolder.XuanCiHolder) holder).questionLine).getChildAt(0).setBackgroundColor(Color.parseColor("#3b7830"));
                        (((TiHolder.XuanCiHolder) holder).questionLine).getChildAt(0).setTag(R.id.selected, 2);
                    }else     if(((TextView)(((TiHolder.XuanCiHolder) holder).questionLine).getChildAt(j)) instanceof AutoResizeTextView){
                        if(((TextView)(((TiHolder.XuanCiHolder) holder).questionLine).getChildAt(j)).getText().toString().contains("_")){
                            if(isAnswer2){
                                (((TiHolder.XuanCiHolder) holder).questionLine).getChildAt(j).setBackgroundColor(Color.parseColor("#3b7830"));
                                (((TiHolder.XuanCiHolder) holder).questionLine).getChildAt(j).setTag(R.id.selected, 2);
                                isAnswer2=false;
                            }else {
                                (((TiHolder.XuanCiHolder) holder).questionLine).getChildAt(j).setBackgroundColor(Color.parseColor("#ffffff"));
                                (((TiHolder.XuanCiHolder) holder).questionLine).getChildAt(j).setTag(R.id.selected, 0);
                            }

                        }else {
                            (((TiHolder.XuanCiHolder) holder).questionLine).getChildAt(j).setBackgroundColor(Color.parseColor("#ffffff"));
                            (((TiHolder.XuanCiHolder) holder).questionLine).getChildAt(j).setTag(R.id.selected, 1);
                        }


                    }

                }
            }
            for (int j = 0; j < list.get(position).getAnswers().size(); j++) {
                wanXingAnswerAdd((((TiHolder.XuanCiHolder) holder).answerLine), list.get(position).getOption().get(j).getOptions(), list.get(position).getAnwser_xuan(), (((TiHolder.XuanCiHolder) holder).questionLine), position);
            }

        } else if (holder instanceof TiHolder.BiaoGeHolder) {//6231类型（表格）
            ((TiHolder.BiaoGeHolder) holder).timu_num.setText(position + 1 + "");
            ArrayList<ArrayList<String>> arrrayOut = list.get(position).getContent();
            (((TiHolder.BiaoGeHolder) holder).tableLayout).removeAllViews();
            (((TiHolder.BiaoGeHolder) holder).answerLine).removeAllViews();
            posBiao = 0;
            for (int i = 0; i < arrrayOut.size(); i++) {
                biaoGeContentAdd((((TiHolder.BiaoGeHolder) holder).tableLayout), arrrayOut, list.get(position).getAnwser_xuan(), (((TiHolder.BiaoGeHolder) holder).answerLine), i, position);
            }

            for (int j = 0; j < list.get(position).getAnswers().size(); j++) {
                biaoGeAnswerAdd((((TiHolder.BiaoGeHolder) holder).answerLine), list.get(position).getOption().get(j).getOptions(), list.get(position).getAnwser_xuan(), (((TiHolder.BiaoGeHolder) holder).tableLayout), position);
            }
        } else if (holder instanceof TiHolder.DanXuanHolder) {//6226 类型（单选）
            ((TiHolder.DanXuanHolder) holder).timu_num.setText(position + 1 + "");
            ((TiHolder.DanXuanHolder) holder).questionLine.removeAllViews();
            ((TiHolder.DanXuanHolder) holder).answerLine.removeAllViews();

            for (int j = 0; j < list.get(position).getContent().size(); j++) {
                danxuanContentAdd((((TiHolder.DanXuanHolder) holder).questionLine), list.get(position).getContent().get(j));
            }
            for (int j = 0; j < list.get(position).getOption().size(); j++) {
                danxuanAnswerAdd((((TiHolder.DanXuanHolder) holder).answerLine), list.get(position).getOption(), list.get(position).getAnswers().get(j), j, position);
            }


        } else if (holder instanceof TiHolder.PanDuanIMGHolder) {  //6228类型（判断图片）
            ((TiHolder.PanDuanIMGHolder) holder).danxuan_title.setText(position + 1 + "");

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < list.get(position).getContent().get(0).size(); i++) {
                sb.append(list.get(position).getContent().get(0).get(i));
            }
            //使用此方法判断，防止点击图片重新加载闪烁问题
            if (sb.toString().equals(((TiHolder.PanDuanIMGHolder) holder).danxuan_image.getTag())) {

            } else {
                // 如果不相同，就加载。现在在这里来改变闪烁的情况
                XImageLoader.load(Const.IMAGE_HEAD + sb.toString(), ((TiHolder.PanDuanIMGHolder) holder).danxuan_image);
                ((TiHolder.PanDuanIMGHolder) holder).danxuan_image.setTag(sb.toString());
            }

            ((TiHolder.PanDuanIMGHolder) holder).answerLine.removeAllViews();
            for (int j = 0; j < list.get(position).getAnswers().size(); j++) {
                panduanImgContentAdd(((TiHolder.PanDuanIMGHolder) holder).answerLine, list.get(position).getOption(), list.get(position).getOption().get(j).getOptions(), j, position);
            }

        } else if (holder instanceof TiHolder.DanCiPXHolder) {//单词拼写  单词听写（6233，6229 类型）两者的区别是拼写每个空一格字符，听写是可以输入多个
            ((TiHolder.DanCiPXHolder) holder).timu_num.setText(position + 1 + "");
            ((TiHolder.DanCiPXHolder) holder).answerLine.removeAllViews();
            posting = 0;
            for (int j = 0; j < list.get(position).getContent().size(); j++) {
                danciPXContentAdd(((TiHolder.DanCiPXHolder) holder).answerLine, list.get(position).getContent().get(j), list.get(position).getAnwser_xuan(), list.get(position).getDt_type(), position);
            }
            for (int j = 0; j < ((TiHolder.DanCiPXHolder) holder).answerLine.getChildCount(); j++) {
                if ("null".equals(((TiHolder.DanCiPXHolder) holder).answerLine.getChildAt(j).getTag(R.id.selected) + "")) {

                } else {
                    if (0 == Integer.parseInt(((TiHolder.DanCiPXHolder) holder).answerLine.getChildAt(j).getTag(R.id.selected) + "")) {
                        // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                        ((TiHolder.DanCiPXHolder) holder).answerLine.getChildAt(j).setBackgroundColor(Color.parseColor("#3b7830"));
                        ((TiHolder.DanCiPXHolder) holder).answerLine.getChildAt(j).setTag(R.id.selected, 2);
                        break;
                    }
                }
            }

        } else if (holder instanceof TiHolder.PanDuanYJHolder) {//6230类型 （判断语句）
            ((TiHolder.PanDuanYJHolder) holder).timu_num.setText(position + 1 + "");
            if (!list.get(position).getQuestion().equals("")) {
                ((TiHolder.PanDuanYJHolder) holder).question.setVisibility(View.VISIBLE);
                ((TiHolder.PanDuanYJHolder) holder).question.setText(list.get(position).getQuestion());
                ((TiHolder.PanDuanYJHolder) holder).question.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.flag_01));
            } else {
                ((TiHolder.PanDuanYJHolder) holder).question.setVisibility(View.GONE);
            }
            ((TiHolder.PanDuanYJHolder) holder).answerLine.removeAllViews();
            ((TiHolder.PanDuanYJHolder) holder).questionLine.removeAllViews();
            for (int j = 0; j < list.get(position).getContent().size(); j++) {
                panduanYJContentAdd(((TiHolder.PanDuanYJHolder) holder).questionLine, list.get(position).getContent().get(j));
            }
            for (int j = 0; j < list.get(position).getOption().size(); j++) {
                panduanYJanswerAdd(((TiHolder.PanDuanYJHolder) holder).answerLine, list.get(position).getOption(), list.get(position).getOption().get(j).getOptions(), j, position);
            }

        } else if (holder instanceof TiHolder.DuiHuaHolder) {//6232 类型 （情景对话）
            ((TiHolder.DuiHuaHolder) holder).timu_num.setText(position + 1 + "");
            ((TiHolder.DuiHuaHolder) holder).answerLine.removeAllViews();
            ((TiHolder.DuiHuaHolder) holder).questionLine.removeAllViews();
            posqing = 0;
            isAnswer2=true;
            isQuestion2=true;

            if(list.size()<=1){
                ((TiHolder.DuiHuaHolder) holder).timu_num.setVisibility(View.GONE);
            }
            for (int j = 0; j < list.get(position).getContent().size(); j++) {
                duihuaContentAdd(((TiHolder.DuiHuaHolder) holder).questionLine, list.get(position).getContent().get(j), list.get(position).getAnwser_xuan(), ((TiHolder.DuiHuaHolder) holder).answerLine, position);
            }
            for (int j = 0; j < list.get(position).getAnswers().size(); j++) {
                Log.d("=========size========","position=="+position+"=="+list.get(position).getAnswers().size()+"=="+list.get(position).getOption().get(j).getOptions());
                duihuaYJanswerAdd(((TiHolder.DuiHuaHolder) holder).answerLine, list.get(position).getOption().get(j).getOptions(), list.get(position).getAnwser_xuan(), ((TiHolder.DuiHuaHolder) holder).questionLine,position);
            }
            for (int j = 0; j < ((TiHolder.DuiHuaHolder) holder).questionLine.getChildCount(); j++) {

                for (int k=0;k<((LinearLayout)((TiHolder.DuiHuaHolder) holder).questionLine.getChildAt(j)).getChildCount();k++){

                    if ("null".equals(((LinearLayout)((TiHolder.DuiHuaHolder) holder).questionLine.getChildAt(j)).getChildAt(k).getTag(R.id.selected) + "")) {

                    } else {
                            // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                            if (list.get(position).getAnwser_xuan() == null) {//当选中的数据中没有数据的时候,
                                ((LinearLayout) ((TiHolder.DuiHuaHolder) holder).questionLine.getChildAt(0)).getChildAt(1).setBackgroundColor(Color.parseColor("#3b7830"));
                                ((LinearLayout) ((TiHolder.DuiHuaHolder) holder).questionLine.getChildAt(0)).getChildAt(1).setTag(R.id.selected, 2);

//                            ((LinearLayout)((TiHolder.DuiHuaHolder) holder).questionLine.getChildAt(0)).getChildAt(k).startAnimation(mAnimation1);
                                break;
                            }else if(isAnswer2&&((LinearLayout) ((TiHolder.DuiHuaHolder) holder).questionLine.getChildAt(j)).getChildAt(k)instanceof AutoResizeTextView
                                    &&((TextView)((LinearLayout) ((TiHolder.DuiHuaHolder) holder)
                                    .questionLine.getChildAt(j)).getChildAt(k)).getText().toString().contains("_")){
                                ((LinearLayout) ((TiHolder.DuiHuaHolder) holder).questionLine.getChildAt(j)).getChildAt(k).setBackgroundColor(Color.parseColor("#3b7830"));
                                ((LinearLayout) ((TiHolder.DuiHuaHolder) holder).questionLine.getChildAt(j)).getChildAt(k).setTag(R.id.selected, 2);
//                                ((LinearLayout)((TiHolder.DuiHuaHolder) holder).questionLine.getChildAt(j)).getChildAt(k).startAnimation(mAnimation1);
                                isAnswer2=false;
                                break;
                            }
                    }
                }

            }
        } else if (holder instanceof TiHolder.XuanZeIMGHolder) {//6203 类型 （图片选择）
            ((TiHolder.XuanZeIMGHolder) holder).two_title.setText(position + 1 + "");

            TiAtwoAdapter adapter = new TiAtwoAdapter(context, list.get(position).getOption(), list.get(position).getAnwser_true(), position, list, R.layout.item_shangcheng01);
            ((TiHolder.XuanZeIMGHolder) holder).goods_gridView.setAdapter(adapter);
        } else if (holder instanceof TiHolder.WanXingHolder) {//6227 类型 （完形填空）

            for (int i = 0; i < list.get(position).getContent().size(); i++) {
                wanxingsContentAdd(((TiHolder.WanXingHolder) holder).questionLine, list.get(position).getContent().get(i));
            }

            listWanXing = list.get(position).getClild();
            //list.get(position).getQuestion()
            if (wanxingAdapter == null) {
                wanxingAdapter = new WanXingTwoAdapter(context, listWanXing);
                ((TiHolder.WanXingHolder) holder).answerLine.setAdapter(wanxingAdapter);
            } else {
                wanxingAdapter.notifyDataSetChanged();
            }


        } else if (holder instanceof Item1ViewHolder) {
            ((Item1ViewHolder) holder).textPrice.setText(list.get(position).getTitle());
        }

    }

    //设置ITEM类型，可以自由发挥，
    @Override
    public int getItemViewType(int position) {
        //Enum类提供了一个ordinal()方法，返回枚举类型的序数
        int t = -1;
        if (list.get(position).getDt_type().equals("6202")) {
            t = ITEM_TYPE.XUANCI.ordinal();
        }
        if (list.get(position).getDt_type().equals("6231")) {
            t = ITEM_TYPE.BIAOGE.ordinal();
        }
        if (list.get(position).getDt_type().equals("6226")) {
            t = ITEM_TYPE.DANXUAN.ordinal();
        }
        if (list.get(position).getDt_type().equals("6228")) {
            t = ITEM_TYPE.PANDUAN_IMG.ordinal();
        }
        if (list.get(position).getDt_type().equals("6233") || list.get(position).getDt_type().equals("6229")) {
            t = ITEM_TYPE.DANCI_PX.ordinal();
        }
        if (list.get(position).getDt_type().equals("6230")) {
            t = ITEM_TYPE.PANDUAN_YJ.ordinal();
        }
        if (list.get(position).getDt_type().equals("6232")) {
            t = ITEM_TYPE.DUIHUA.ordinal();
        }
        if (list.get(position).getDt_type().equals("6203")) {
            t = ITEM_TYPE.XUANZE_IMG.ordinal();
        }
        if (list.get(position).getDt_type().equals("6227")) {
            t = ITEM_TYPE.WANXING.ordinal();
        }
        if (list.get(position).getDt_type().equals("623333")) {
            t = ITEM_TYPE.ITEM2.ordinal();
        }
        return t;
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    //item1 的ViewHolder
    public static class Item1ViewHolder extends RecyclerView.ViewHolder {
        public TextView textPrice;

        public Item1ViewHolder(View itemView) {
            super(itemView);
            textPrice = (TextView) itemView.findViewById(R.id.textPrice);
        }
    }

    /**
     * 内容( 6202类型    仿写，单词拼写，选词填空等)
     */
    private void wanXingContentAdd(final FlowLayout questionLine, ArrayList<ArrayList<String>> arrrayOut, ArrayList<String> xuan, final FlowLayout answerLine, int i, final int position) {

        Log.d("====wanXingContentAdd==","wanXingContentAdd");
        for (int j = 0; j < arrrayOut.get(i).size(); j++) {
            RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            params.setMargins(0, 5, 0, 5);
            if ("_".equals(arrrayOut.get(i).get(j))) {
                posxuan++;
                AutoResizeTextView textView = new AutoResizeTextView(context);
                if (xuan != null && !xuan.equals("")) {//注：Listview下拉后会清除数据 ，保存到这里（代表选中的），然后判断不为空的时候加载到数据中
                    textView.setText(Html.fromHtml("<u>" + xuan.get(posxuan - 1) + "" + "</u>"));
                    textView.setTag(R.id.selected,1);
                } else {
                    textView.setText(arrrayOut.get(i).get(j) + "__");
                    textView.setTag(R.id.selected,0);
                }
                textView.setTextSize(16);
                textView.setTextColor(Color.parseColor("#3b7830"));
                textView.setTag(R.id.selected, 0);
                textView.setPadding(15, 0, 15, 0);

                textView.setLayoutParams(params);
                questionLine.addView(textView);
                //点击事件
                textView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // 这个要分两个方法去做
                        if ("___".equals(((TextView) v).getText() + "")) {
                            // 无填好的内容
                            for (int i = 0; i < questionLine.getChildCount(); i++) {
                                // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                                if ("2".equals(questionLine.getChildAt(i).getTag(R.id.selected) + "")) {
                                    questionLine.getChildAt(i).setBackgroundColor(Color.parseColor("#ffffff" + ""));
                                    questionLine.getChildAt(i).setTag(R.id.selected, 0);
                                    break;
                                }
                            }
                            ((TextView) v).setBackgroundColor(Color.parseColor("#3b7830"));
                            // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                            ((TextView) v).setTag(R.id.selected, 2);


                        } else {
                            // 有填好的内容
                            for (int i = 0; i < questionLine.getChildCount(); i++) {
                                // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                                if ("2".equals(questionLine.getChildAt(i).getTag(R.id.selected) + "")) {
                                    questionLine.getChildAt(i).setBackgroundColor(Color.parseColor("#ffffff" + ""));
                                    questionLine.getChildAt(i).setTag(R.id.selected, 0);
                                }
                            }
                            for (int i = 0; i < answerLine.getChildCount(); i++) {
                                Log.d("========","lenth======"+((TextView) v).getText().toString().length());
                                //从首字母之后开始比较
                                if(((TextView) v).getText().toString().length()<=2){
                                    Log.d("========","neirong======"+((TextView) v).getText().toString()+"==="+((TextView) answerLine.getChildAt(i)).getText().toString());
                                    if(((TextView) v).getText().toString().trim()
                                            .equals(((TextView) answerLine.getChildAt(i)).getText().toString().trim())&&"3".equals(((TextView) answerLine.getChildAt(i)).getTag(R.id.selected)+"")){
                                        ((TextView) answerLine.getChildAt(i))
                                                .setBackgroundDrawable(context.getResources().getDrawable(R.drawable.flag_01));
                                        // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                                        ((TextView) answerLine.getChildAt(i)).setTag(R.id.selected, 1);
                                        ((TextView) answerLine.getChildAt(i)).setEnabled(true);
                                        ((TextView) answerLine.getChildAt(i)).setClickable(true);
                                        break;
                                    }
                                }else {
                                    if ((((TextView) v).getText().toString().trim().substring(1))
                                            .equals((((TextView) answerLine.getChildAt(i)).getText().toString().trim().substring(1)))&&"3".equals(((TextView) answerLine.getChildAt(i)).getTag(R.id.selected)+"")) {
                                        ((TextView) answerLine.getChildAt(i))
                                                .setBackgroundDrawable(context.getResources().getDrawable(R.drawable.flag_01));
                                        // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                                        ((TextView) answerLine.getChildAt(i)).setTag(R.id.selected, 1);
                                        ((TextView) answerLine.getChildAt(i)).setEnabled(true);
                                        ((TextView) answerLine.getChildAt(i)).setClickable(true);
                                        break;
                                    }
                                }

                            }
                            ((TextView) v).setText("___");
                            ((TextView) v).setBackgroundColor(Color.parseColor("#3b7830"));
                            // tag标记位 0 无数据未选中 1有数据未选-中 2无数据选中 3有数据选中
                            ((TextView) v).setTag(R.id.selected, 2);
                        }

                        //点击内容的时候遍历出答案是否正确
                        StringBuffer sb = new StringBuffer();
                        ArrayList<String> anser = new ArrayList<String>();
                        for (int i = 0; i < questionLine.getChildCount(); i++) {
                            if (questionLine.getChildAt(i) instanceof AutoResizeTextView) {
                                String to = ((TextView) questionLine.getChildAt(i)).getText().toString().trim();
                                sb.append(to);
                                anser.add(to);
                            }
                        }
                        list.get(position).setAnwser_xuan(anser);//注：Listview下拉后会清除数据 ，保存到这里（代表选中的），然后判断不为空的时候加载到数据中

                        StringBuilder ssss = new StringBuilder();
                        for (int j = 0; j < list.get(position).getAnwser_true().size(); j++) {
                            ssss.append(list.get(position).getAnwser_true().get(j).trim());
                        }
                        System.out.println("WANXING6020:" + sb);
                        System.out.println("WANXING6020:" + ssss);
                        if (sb.equals("")) {//当没有选择答案的时候
                            list.get(position).setXuan(2);
                        } else if (sb.toString().contains("___")) {//因为空的字符串未"___"，所以这里判断当里面包含这个字符的时候代表未选中
                            list.get(position).setXuan(2);
                        } else if (sb.toString().trim().equalsIgnoreCase(ssss.toString().trim())) {
                            list.get(position).setXuan(0);//0代表选择正确
                        } else {
                            list.get(position).setXuan(1);
                        }
                    }
                });

            } else {
                TextView textView = new TextView(context);
                textView.setText(arrrayOut.get(i).get(j));
                textView.setTextSize(16);
                textView.setTextColor(Color.parseColor("#3b7830"));
                textView.setLayoutParams(params);
                questionLine.addView(textView);
            }

        }

    }

    /**
     * 答案( 6202类型    仿写，单词拼写，选词填空等)
     */
    private void wanXingAnswerAdd(FlowLayout answerLine, String string, ArrayList<String> xuan, final FlowLayout questionLine, final int position) {
        // 设置添加的textvIew的参数

        RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        params.setMargins(0, 5, 25, 5);
        TextView textView = new TextView(context);
        textView.setText(string);
        textView.setTextSize(16);
        textView.setMinWidth(50);
        textView.setGravity(Gravity.CENTER);
        textView.setTextColor(Color.parseColor("#ffffff"));
        textView.setTag(R.id.selected,1);
        textView.setLayoutParams(params);
        textView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.flag_01));
        answerLine.addView(textView);
        if (xuan != null && !xuan.equals("")) {
            for (int i = 0; i < xuan.size(); i++) {
                if (string.trim().equals(xuan.get(i).trim())) {
                    textView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.flag_04));
                    textView.setTag(R.id.selected,3);
                    textView.setEnabled(false);
                    textView.setClickable(false);
                }
            }
        }
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               Log.d("========","tag=="+v.getTag());
               //问题最后一项判断是否是句子还是单词
                String last = ((TextView) questionLine.getChildAt(questionLine.getChildCount() - 1)).getText().toString();
//                if("3".equals(v.getTag(R.id.selected)+"")){
//                    return;
//                }
                for (int i = 0; i < questionLine.getChildCount(); i++) {

                    // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                    if ("2".equals(questionLine.getChildAt(i).getTag(R.id.selected) + "")) {

                        //首字母大写
                        String danci = ((TextView) v).getText().toString();

                        Log.d("=======","neirong==="+danci+"=="+danci.trim().length());
                        Log.d("====last===",last);
                        if (i==0&&"?!.".contains(last.trim())){
                            ((TextView) questionLine.getChildAt(i)).setText(Html.fromHtml("<u>" + danci.substring(0, 1).toUpperCase() + danci.substring(1) + "" + "</u>"));
                        }else {
                            ((TextView) questionLine.getChildAt(i)).setText(Html.fromHtml("<u>" + ((TextView) v).getText() + "" + "</u>"));
                        }
//
//                        if (i == 0&&danci.trim().length()>=2) {
//                            Log.d("=======","neirong====="+danci);
//
//                        } else {
//
//                        }

                        v.setEnabled(false);
                        v.setClickable(false);
                        v.setTag(R.id.selected,3);
                        ((TextView) v).setBackgroundDrawable(context.getResources().getDrawable(R.drawable.flag_04));
                        // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                        questionLine.getChildAt(i).setTag(R.id.selected, 1);
                        for (int j = 0; j < questionLine.getChildCount(); j++) {
                            questionLine.getChildAt(j).setBackgroundColor(Color.parseColor("#ffffff"));
                        }
                        for (int j = 0; j < questionLine.getChildCount(); j++) {
                            // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                            if ("0".equals(questionLine.getChildAt(j).getTag(R.id.selected) + "")) {
                                questionLine.getChildAt(j).setBackgroundColor(Color.parseColor("#3b7830"));
                                // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                                questionLine.getChildAt(j).setTag(R.id.selected, 2);
                                break;
                            }
                        }
                        break;
                    }
                }
                //点击的时候答案遍历出答案是否正确
                StringBuffer sb = new StringBuffer();
                ArrayList<String> anser = new ArrayList<String>();
                for (int i = 0; i < questionLine.getChildCount(); i++) {
                    if (questionLine.getChildAt(i) instanceof AutoResizeTextView) {
                        String to = ((TextView) questionLine.getChildAt(i)).getText().toString().trim();
                        sb.append(to);
                        anser.add(to);
                    }
                }
                list.get(position).setAnwser_xuan(anser);//注：Listview下拉后会清除数据 ，保存到这里（代表选中的），然后判断不为空的时候加载到数据中

                StringBuilder ssss = new StringBuilder();
                for (int j = 0; j < list.get(position).getAnwser_true().size(); j++) {
                    ssss.append(list.get(position).getAnwser_true().get(j).trim());
                }
                System.out.println("UIIHIUHHOIH" + sb);
                System.out.println("UIIHIUHHOIH" + ssss);
                if (sb.equals("")) {
                    list.get(position).setXuan(2);
                } else if (sb.toString().trim().equalsIgnoreCase(ssss.toString().trim())) {
                    list.get(position).setXuan(0);//0代表选择正确
                } else {
                    list.get(position).setXuan(1);
                }
            }
        });
    }

    /**
     * 内容( 6231类型   表格)
     *
     * @param tableLayout
     * @param arrrayOut   内容
     * @param xuan        选中的答案
     * @param answerLine
     * @param i
     * @param p           position
     */
    private void biaoGeContentAdd(final TableLayout tableLayout, ArrayList<ArrayList<String>> arrrayOut, ArrayList<String> xuan, final FlowLayout answerLine, final int i, final int p) {
        // 设置所有的item都可伸缩扩展
        int heigh=0;
        tableLayout.setStretchAllColumns(true);//可伸展
        tableLayout.setShrinkAllColumns(true);//可压缩
        Log.d("==biaoGeContentAdd","biaoGeContentAdd");
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//        LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        //生成10行，8列的表格
        totalEdit = 0;
        LinearLayout tableRow = new LinearLayout(context);
        tableRow.setOrientation(LinearLayout.HORIZONTAL);
        tableRow.setGravity(Gravity.CENTER);
        tableRow.setBackgroundResource(R.drawable.table_frame_gray);
        for (int j = 0; j < arrrayOut.get(i).size(); j++) {

            if ("_".equals(arrrayOut.get(i).get(j))) {
                posBiao++;
                AutoResizeTextView tv = new AutoResizeTextView(context);
                tv.setGravity(Gravity.CENTER);
//                tv.setLayoutParams(params);
                if (xuan != null && !xuan.equals("")) {
                    tv.setText(xuan.get(posBiao - 1));
                }
                tv.setBackgroundResource(R.drawable.table_frame_gray);
                tv.setTag(totalEdit);
                tv.setWidth(1);//平分布局
                tv.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT,1.0f));
//                tv.setLines(1);//固定设置一行
                tv.setPadding(10, 20, 10, 20);
             //   totalEdit++;//(测试  先去掉)
                tv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        TextView editText = (TextView) v;
                        String ed = editText.getText().toString();
                        for (int i = 0; i < answerLine.getChildCount(); i++) {
                            TextView button = (TextView) answerLine.getChildAt(i);
                            String btn_text = button.getText().toString();
                            if (btn_text.equals(ed)&&"3".equals(answerLine.getChildAt(i).getTag(R.id.selected)+"")) {
                                answerLine.getChildAt(i).setBackgroundDrawable(context.getResources().getDrawable(R.drawable.flag_01));
                                answerLine.getChildAt(i).setSelected(false);
                                // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                                answerLine.getChildAt(i).setTag(R.id.selected,1);
                                break;
                            }
                        }
                        ((TextView) v).setText("");
                        ArrayList<String> anser = new ArrayList<String>();
                        for (int i = 0; i < tableLayout.getChildCount(); i++) {
                            LinearLayout tableRow = (LinearLayout) tableLayout.getChildAt(i);
                            for (int i1 = 0; i1 < tableRow.getChildCount(); i1++) {
                                if (tableRow.getChildAt(i1) instanceof AutoResizeTextView) {
                                    tableRow.getChildAt(i1).setBackgroundResource(R.drawable.table_frame_gray);
                                    tableRow.getChildAt(i1).setSelected(false);

                                    String to = ((TextView) tableRow.getChildAt(i1)).getText().toString();
                                    anser.add(to);
                                }
                            }
                        }
                        list.get(p).setAnwser_xuan(anser);//注：Listview下拉后会清除数据 ，保存到这里（代表选中的），然后判断不为空的时候加载到数据中

                        v.setSelected(true);
                        v.setBackgroundColor(Color.parseColor("#3b7830"));
                    }
                });
                if (posBiao-1==0) {
                    tv.setSelected(true);
                    tv.setBackgroundColor(Color.parseColor("#3b7830"));
                    firstRow = false;
                }
                tableRow.addView(tv);
                heigh = Math.max(heigh,tableRow.getHeight());
            } else {
                AutoResizeTwoTextView tv = new AutoResizeTwoTextView(context);
//                tv.setLayoutParams(params);
                tv.setText(arrrayOut.get(i).get(j));
                tv.setPadding(10, 20, 10, 20);
                tv.setBackgroundResource(R.drawable.table_frame_gray);
                tv.setGravity(Gravity.CENTER);
                tv.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT,1.0f));
                tv.setWidth(1);//平分布局
//                tv.setLines(1);//固定设置一行
                tableRow.addView(tv);
                heigh = Math.max(heigh,tableRow.getHeight());

            }
        }

        //新建的TableRow添加到TableLayout
        tableLayout.addView(tableRow, lp);
    }


    /**
     * 答案( 6231类型   表格)
     *
     * @param answerLine
     * @param string
     * @param xuan        选中的答案
     * @param tableLayout
     * @param p           position
     */
    private void biaoGeAnswerAdd(FlowLayout answerLine, String string, ArrayList<String> xuan, final TableLayout tableLayout, final int p) {
        // 设置添加的textvIew的参数
        Log.d("--------",string);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        params.setMargins(0, 5, 25, 5);
        TextView textView = new TextView(context);
        textView.setText(string);
        textView.setTag(R.id.selected,1);
        textView.setTextSize(15);
        textView.setClickable(true);
        textView.setTextColor(Color.parseColor("#ffffff"));
        textView.setLayoutParams(params);
        textView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.flag_01));

        answerLine.addView(textView);
        if (xuan != null && !xuan.equals("")) {
            for (int i = 0; i < xuan.size(); i++) {
                if (string.equals(xuan.get(i))) {
                    textView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.flag_04));
                    textView.setSelected(false);
                }
            }
        }
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //先判断有没有选中的编辑框
                boolean hasSelect = false;
                v.setTag(R.id.selected,3);
                for (int i = 0; i < tableLayout.getChildCount(); i++) {
                    System.out.println(tableLayout.getChildAt(i) + ">>>外层");
                    LinearLayout tableRow = (LinearLayout) tableLayout.getChildAt(i);
                    for (int i1 = 0; i1 < tableRow.getChildCount(); i1++) {
                        if (tableRow.getChildAt(i1) instanceof AutoResizeTextView && tableRow.getChildAt(i1).isSelected()) {
                            hasSelect = true;
                            break;
                        }
                    }
                }
                if (!hasSelect) {
                    return;
                }
                if (v.isSelected()) {

                } else {
                    ((TextView) v).setBackgroundDrawable(context.getResources().getDrawable(R.drawable.flag_04));
                    v.setSelected(true);
                    for (int i = 0; i < tableLayout.getChildCount(); i++) {
                        LinearLayout tableRow = (LinearLayout) tableLayout.getChildAt(i);
                        for (int i1 = 0; i1 < tableRow.getChildCount(); i1++) {
                            if (tableRow.getChildAt(i1) instanceof AutoResizeTextView && tableRow.getChildAt(i1).isSelected()) {
                                positionbbb = Integer.parseInt(tableRow.getChildAt(i1).getTag() + "");

                                ((AutoResizeTextView) tableRow.getChildAt(i1)).setText(((TextView) v).getText().toString());
                                tableRow.getChildAt(i1).setBackgroundResource(R.drawable.table_frame_gray);
                                tableRow.getChildAt(i1).setSelected(false);
                            }
                        }
                    }
                    int totalPeroid = 2;
                    boolean hasFind = false;
                    while (totalPeroid >= 0) {
                        totalPeroid--;
                        positionbbb++;
                        if (positionbbb > totalEdit - 1) {
                            positionbbb = 0;
                        }
                        outer:
                        for (int i = 0; i < tableLayout.getChildCount(); i++) {
                            LinearLayout tableRow = (LinearLayout) tableLayout.getChildAt(i);

                            for (int i1 = 0; i1 < tableRow.getChildCount(); i1++) {
                                if (tableRow.getChildAt(i1) instanceof AutoResizeTextView) {
                                    AutoResizeTextView ed = (AutoResizeTextView) tableRow.getChildAt(i1);
                                    if (Integer.valueOf(ed.getTag() + "") == positionbbb && ed.getText().toString().equals("")) {
                                        tableRow.getChildAt(i1).setBackgroundColor(Color.parseColor("#3b7830"));
                                        tableRow.getChildAt(i1).setSelected(true);
                                        totalPeroid = -1;
                                        hasFind = true;
                                        break outer;
                                    } else {
                                        hasFind = false;
                                    }
                                }
                            }
                        }
                    }
                }

                //点击的时候遍历出答案是否正确
                StringBuffer sb = new StringBuffer();
                ArrayList<String> anser = new ArrayList<String>();
                for (int i = 0; i < tableLayout.getChildCount(); i++) {

                    LinearLayout tableRow = (LinearLayout) tableLayout.getChildAt(i);
                    for (int i1 = 0; i1 < tableRow.getChildCount(); i1++) {
                        if (tableRow.getChildAt(i1) instanceof AutoResizeTextView) {
                            String to = ((TextView) tableRow.getChildAt(i1)).getText().toString();
                            sb.append(to);
                            anser.add(to);
                        }
                    }
                }
                list.get(p).setAnwser_xuan(anser);//注：Listview下拉后会清除数据 ，保存到这里（代表选中的），然后判断不为空的时候加载到数据中

                StringBuilder ssss = new StringBuilder();
                for (int j = 0; j < list.get(p).getAnwser_true().size(); j++) {
                    ssss.append(list.get(p).getAnwser_true().get(j));
                }
                System.out.println("UIIHIUHHOIS" + sb);
                System.out.println("UIIHIUHHOIS" + ssss);
                if (sb.equals("")) {
                    list.get(p).setXuan(2);//2代表没有输入
                } else if (sb.toString().equals(ssss.toString())) {
                    list.get(p).setXuan(0);//0代表选择正确
                } else {
                    list.get(p).setXuan(1);//0代表选择错误
                }
            }
        });
    }

    /**
     * 内容( 6231类型   单选)
     */
    private void danxuanContentAdd(final FlowLayout questionLine, ArrayList<String> string) {
        RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        params.setMargins(0, 5, 0, 5);
        for (int i = 0; i < string.size(); i++) {
            if ("_".equals(string)) {
                TextView textView = new TextView(context);
                textView.setText(string.get(i) + "__");
                textView.setTextSize(16);
                textView.setTextColor(Color.parseColor("#3b7830"));
                textView.setPadding(15, 0, 15, 0);
                textView.setLayoutParams(params);
                questionLine.addView(textView);

            } else {
                TextView textView = new TextView(context);
                textView.setText(string.get(i));
                textView.setTextSize(16);
                textView.setTextColor(Color.parseColor("#3b7830"));
                textView.setLayoutParams(params);
                questionLine.addView(textView);
            }
        }
    }

    /**
     * 答案( 6231类型   单选)
     */
    private void danxuanAnswerAdd(final FlowLayout answerLine, final ArrayList<TIbean.Options> qianzhui, String content, final int j, final int position) {
        // 设置添加的textvIew的参数
        RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT);
        params.setMargins(0, 5, 25, 5);

        final View innerView = LayoutInflater.from(MyApplication.instance).inflate(R.layout.item_a3, null, false);
        final TextView a3_title = (TextView) innerView.findViewById(R.id.a3_title);
        final TextView a3_content = (TextView) innerView.findViewById(R.id.a3_content);
        final ImageView a3_img = (ImageView) innerView.findViewById(R.id.a3_img);
        final RelativeLayout a3_layout = (RelativeLayout) innerView.findViewById(R.id.a3_layout);
        a3_title.setText(qianzhui.get(j).getOptions());
        a3_content.setText(content);
        answerLine.addView(innerView, params);

        if (qianzhui.get(j).isDa()) {
            a3_layout.setBackgroundResource(R.drawable.shape_a33);
            a3_title.setBackgroundResource(R.color.olive_green);
            a3_title.setTextColor(context.getResources().getColor(R.color.white));
            a3_img.setVisibility(View.VISIBLE);
        } else {
            a3_layout.setBackgroundResource(R.drawable.shape_a3);
            a3_title.setBackgroundResource(R.color.gray_D6);
            a3_title.setTextColor(context.getResources().getColor(R.color.blue));
            a3_img.setVisibility(View.GONE);
        }
        innerView.setTag(R.id.tag, qianzhui.get(j).getOptions());
        innerView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i = 0; i < qianzhui.size(); i++) {
                    qianzhui.get(i).setDa(false);
                }
                qianzhui.get(j).setDa(true);
                ArrayList<String> answer_truev = list.get(position).getAnwser_true();
                int poistions = answer_truev.indexOf(innerView.getTag(R.id.tag).toString());
                if (poistions == -1) {
                    list.get(position).setXuan(1);//1代表选择错误
                } else {
                    list.get(position).setXuan(0);//0代表选择正确
                }
                notifyDataSetChanged();
            }
        });
    }


    /**
     * 答案（6228类型  图片判断）
     */
    private void panduanImgContentAdd(LinearLayout answerLine, final ArrayList<TIbean.Options> qianzhui, String string, final int j, final int position) {
        // 设置添加的textvIew的参数
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
        params.setMargins(70, 5, 70, 5);
        final TextView textView = new TextView(context);
        if("0".equals(string)){
            textView.setText("×");
        }else if ("1".equals(string)){
            textView.setText("√");
        }else {
            textView.setText(string);
        }
        textView.setTextSize(20);
        textView.setGravity(Gravity.CENTER);
        textView.setTextColor(Color.parseColor("#008000"));//默认是字体是绿色
        textView.setLayoutParams(params);
        textView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.bg_stroke_green));
        answerLine.addView(textView);

        if (qianzhui.get(j).isDa()) {
            textView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.bg_corner_green));//选中状态
            textView.setTextColor(Color.WHITE);
        } else {
            textView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.bg_stroke_green));//未选中状态
            textView.setTextColor(Color.parseColor("#008000"));
        }
        textView.setTag(R.id.tag, qianzhui.get(j).getOptions());
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i = 0; i < qianzhui.size(); i++) {
                    qianzhui.get(i).setDa(false);
                }
                qianzhui.get(j).setDa(true);
                ArrayList<String> answer_truev = list.get(position).getAnwser_true();
                int poistions = answer_truev.indexOf(textView.getTag(R.id.tag).toString());
                if (poistions == -1) {
                    list.get(position).setXuan(1);//1代表选择错误
                } else {
                    list.get(position).setXuan(0);//0代表选择正确
                }
                notifyDataSetChanged();
            }
        });
    }


    /**
     * 内容  单词拼写  单词听写（6233，6229 类型）两者的区别是拼写每个空一格字符，听写是可以输入多个
     *
     * @param questionLine
     * @param string
     * @param xuan         已经选好的数据
     * @param type         标示类型
     * @param position
     */
    private void danciPXContentAdd(final FlowLayout questionLine, ArrayList<String> string, ArrayList<String> xuan, final String type, final int position) {
        for (int i = 0; i < string.size(); i++) {
            Log.d("danciPXContentAdd","danciPXContentAdd");
            RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            params.setMargins(2, 0, 2, 0);
            final LineEditText editText = new LineEditText(context);
            if ("_".equals(string.get(i))) {
                posting++;

                if (type.equals("6233")) {
                    editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1)});
//
                }
                if (xuan != null && !xuan.equals("")) {
                    editText.setText(xuan.get(posting - 1));//注：Listview下拉后会清除数据 ，保存到这里（代表选中的），然后判断不为空的时候加载到数据中
                }
                editText.setMaxWidth(40);
                editText.setMinWidth(30);
                editText.setTextSize(16);
                editText.setTag(R.id.selected, 0);
                editText.setPadding(10, 0, 10, 0);
                editText.setBackgroundColor(Color.parseColor("#ffffff"));
                editText.setCursorVisible(false);
                editText.setLayoutParams(params);
                editText.clearFocus();
                questionLine.addView(editText);
                editText.setTag(false);
//                for (int m = 0; m < questionLine.getChildCount(); m++) {
//                    if (questionLine.getChildAt(m) instanceof LineEditText) {
//                        if(!Boolean.valueOf(questionLine.getChildAt(m).getTag()+"")){
//                            questionLine.getChildAt(m).clearFocus();
//                        }
//                    }
//
//                }
                //点击事件
                editText.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                    v.setFocusable(true);
                    ((LineEditText) v).setText("");
                    ((LineEditText) v).setBackgroundColor(Color.parseColor("#3b7830"));
                        // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                    ((LineEditText) v).setTag(R.id.selected, 2);
                    }
                });
                editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                    @Override
                    public void onFocusChange(View v, boolean hasFocus) {
//
//                        if (hasFocus){
//                            Log.d("=======setOnFocus====","true");
//                            editText.setText("");
//                        }else {
//                            Log.d("=======setOnFocus====","false");
//                        }

                        // 这个要分两个方法去做
                        if ("".equals(((EditText) v).getText() + "")) {
                            // 无填好的内容
                            for (int i = 0; i < questionLine.getChildCount(); i++) {
                                // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                                if ("2".equals(questionLine.getChildAt(i).getTag(R.id.selected) + "")) {
                                    questionLine.getChildAt(i).setBackgroundColor(Color.parseColor("#ffffff" + ""));
                                    questionLine.getChildAt(i).setTag(R.id.selected, 0);
//                                    questionLine.getChildAt(i).clearFocus();
                                    questionLine.getChildAt(i).setTag(false);
                                    break;
                                }

                            }


                        } else {
                            if(!hasFocus){
                                // 有填好的内容

                                Log.d("==hasFocus==","flase");
                                for (int i = 0; i < questionLine.getChildCount(); i++) {
                                    // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                                    if ("2".equals(questionLine.getChildAt(i).getTag(R.id.selected) + "")) {
                                        questionLine.getChildAt(i).setBackgroundColor(Color.parseColor("#ffffff" + ""));
                                        questionLine.getChildAt(i).setTag(R.id.selected, 0);
//                                        questionLine.getChildAt(i).clearFocus();
                                    }

                                }
                                return;

                            }else {
                                Log.d("==hasFocus==","true");
                                for (int i = 0; i < questionLine.getChildCount(); i++) {
                                    // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                                    if (Boolean.valueOf(questionLine.getChildAt(i).getTag()+"")) {
                                        questionLine.getChildAt(i).setBackgroundColor(Color.parseColor("#ffffff" + ""));
                                        questionLine.getChildAt(i).setTag(false);
                                        questionLine.getChildAt(i).clearFocus();
                                    }

                                }
//                                InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
//                                imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
                                ((LineEditText) v).setText("");


                            }


                        }

                        ((LineEditText) v).setBackgroundColor(Color.parseColor("#3b7830"));
                        // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                        ((LineEditText) v).setTag(R.id.selected, 2);
                        v.setTag(true);
                    }
                });

//
                editText.addTextChangedListener(new TextWatcher() {

                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                        Log.d("========addtexat==","addTextChangedListener");
//                        if (!"".equals(s.toString())){
//                            editText.setBackgroundColor(Color.parseColor("#ffffff" + ""));
//                            editText.setTag(R.id.selected, 1);
//
//                        }

                    }

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                        StringBuffer sb = new StringBuffer();
                        ArrayList<String> anser = new ArrayList<String>();
                        for (int i = 0; i < questionLine.getChildCount(); i++) {
                            if (questionLine.getChildAt(i) instanceof EditText) {
                                String to = ((EditText) questionLine.getChildAt(i)).getText().toString().trim();
                                sb.append(to);
                                anser.add(to);
                            }
                        }
                        list.get(position).setAnwser_xuan(anser);//注：Listview下拉后会清除数据 ，保存到这里（代表选中的），然后判断不为空的时候加载到数据中

                        StringBuilder ssss = new StringBuilder();
                        for (int j = 0; j < list.get(position).getAnwser_true().size(); j++) {
                            ssss.append(list.get(position).getAnwser_true().get(j).trim());
                        }
                        System.out.println("UIIHIUHHOIH" + sb);
                        System.out.println("UIIHIUHHOIH" + ssss);
                        if (sb.equals("")) {
                            list.get(position).setXuan(2);
                        } else if (sb.toString().trim().equals(ssss.toString().trim())) {
                            list.get(position).setXuan(0);//0代表选择正确
                        } else {
                            list.get(position).setXuan(1);
                        }


                        if (type.equals("6233")) {
                            if (s.length() >= 1) {
                                int index = 0;
                                for (int i1 = 0; i1 < questionLine.getChildCount(); i1++) {
                                    questionLine.getChildAt(i1).setBackgroundColor(Color.parseColor("#ffffff" + ""));
//                                    questionLine.getChildAt(i1).setTag(R.id.selected, 1);
                                    if (Boolean.valueOf(questionLine.getChildAt(i1).getTag() + "")) {
                                        index = i1;
//                                        questionLine.getChildAt(i1).clearFocus();

                                    }
                                    questionLine.getChildAt(i1).setTag(false);

                                    if (index == questionLine.getChildCount() - 1) {
                                        index = -1;
                                    }
                                }
                                for (int i = 0; i < questionLine.getChildCount(); i++) {

                                    if (questionLine.getChildAt(i) instanceof LineEditText) {
                                            if("".equals(((LineEditText) questionLine.getChildAt(i)).getText().toString())){
                                                questionLine.getChildAt(i).setTag(true);
                                                questionLine.getChildAt(i).requestFocus();
                                                questionLine.getChildAt(i).setFocusable(true);
                                                questionLine.getChildAt(i).setFocusableInTouchMode(true);
                                                questionLine.getChildAt(i).setBackgroundColor(Color.parseColor("#3b7830" + ""));
                                                questionLine.getChildAt(i).setTag(R.id.selected, 2);
                                                break;
                                            }

                                    }

                                }


                            }
                        }


                    }

                    @Override
                    public void afterTextChanged(Editable s) {

                    }
                });

            } else {
                TextView textView = new TextView(context);
                textView.setText(string.get(i));
                textView.setTextSize(16);
                textView.setTextColor(Color.parseColor("#3b7830"));
                textView.setLayoutParams(params);
                questionLine.addView(textView);
            }
        }
    }


    /**
     * 内容 （6230类型  语句判断）
     */
    private void panduanYJContentAdd(final FlowLayout questionLine, ArrayList<String> string) {
        for (int i = 0; i < string.size(); i++) {
            RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            params.setMargins(0, 5, 0, 5);

            if ("_".equals(string.get(i))) {
                TextView textView = new TextView(context);
                textView.setText(string.get(i) + "__");
                textView.setTextSize(16);
                textView.setTextColor(Color.parseColor("#3b7830"));
                textView.setPadding(15, 0, 15, 0);
                textView.setLayoutParams(params);
                questionLine.addView(textView);

            } else {
                TextView textView = new TextView(context);
                textView.setText(string.get(i));
                textView.setTextSize(16);
                textView.setTextColor(Color.parseColor("#3b7830"));
                textView.setLayoutParams(params);
                questionLine.addView(textView);
            }
        }
    }

    /**
     * 答案（6230类型  语句判断）
     */
    private void panduanYJanswerAdd(LinearLayout answerLine, final ArrayList<TIbean.Options> qianzhui, String string, final int j, final int position) {
        // 设置添加的textvIew的参数
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
        params.setMargins(40, 5, 40, 5);
        final TextView textView = new TextView(context);
        textView.setText(string);
        textView.setTextSize(12);
        textView.setTextColor(Color.parseColor("#008000"));
        textView.setGravity(Gravity.CENTER);
        textView.setLayoutParams(params);
        textView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.bg_stroke_green));
        answerLine.addView(textView);

        if (qianzhui.get(j).isDa()) {
            textView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.bg_corner_green));
            textView.setTextColor(Color.WHITE);
        } else {
            textView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.bg_stroke_green));
            textView.setTextColor(Color.parseColor("#008000"));
        }
        textView.setTag(R.id.tag, qianzhui.get(j).getOptions());
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i = 0; i < qianzhui.size(); i++) {
                    qianzhui.get(i).setDa(false);
                }
                qianzhui.get(j).setDa(true);
                ArrayList<String> answer_truev = list.get(position).getAnwser_true();
                int poistions = answer_truev.indexOf(textView.getTag(R.id.tag).toString());
                if (poistions == -1) {
                    list.get(position).setXuan(1);//1代表选择错误
                } else {
                    list.get(position).setXuan(0);//0代表选择正确
                }
                notifyDataSetChanged();
            }
        });
    }

    /**
     * 内容（6232类型  情景对话）
     */

    private void duihuaContentAdd(final LinearLayout questionLine, ArrayList<String> string, ArrayList<String> xuan, final FlowLayout answerLine, final int position) {
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
            params.setMargins(0, 0, 25, 0);
        params.setMargins(0, 5, 0, 5);
        final MyLinearLayout linearLayout1 = new MyLinearLayout(context);
        linearLayout1.setLayoutParams(params);
        linearLayout1.setOrientation(LinearLayout.HORIZONTAL);

        for (int i = 0; i < string.size(); i++) {
            if ("_".equals(string.get(i))) {
                posqing++;
                AutoResizeTextView textView = new AutoResizeTextView(context);
                textView.setText(string.get(i) + "______");
                textView.setTextSize(14);
                textView.setFocusable(false);
                textView.setTextColor(Color.parseColor("#3b7830"));
                textView.setTag(R.id.selected, 0);
                textView.setPadding(15, 0, 15, 0);
                textView.setLayoutParams(params);

                Log.d("====listtag=",textView.getTag(R.id.selected)+"==="+position);
                if (xuan != null && !xuan.equals("")) {//注：Listview下拉后会清除数据 ，保存到这里（代表选中的），然后判断不为空的时候加载到数据中
                    textView.setText(Html.fromHtml("<u>" + xuan.get(posqing - 1) + "" + "</u>"));
                    if (!xuan.get(posqing-1).equals(string.get(i) + "______")){
                        textView.setTag(R.id.selected,1);
                    } else if ("______".equals(textView.getText() + "")&&isQuestion2){
                            textView.setTag(R.id.selected,2);
                            textView.setBackgroundColor(Color.parseColor("#3b7830"));
                            break;
                    }else {
                        textView.setTag(R.id.selected,0);
                    }
                    for (int k=0;k<answerLine.getChildCount();k++){
                        if(xuan.get(posqing-1).equals(((TextView)answerLine.getChildAt(k)).getText().toString())){
                            answerLine.getChildAt(k).setClickable(false);
                            answerLine.getChildAt(k).setTag(R.id.selected,3);
                        }else {
                            answerLine.getChildAt(k).setClickable(true);
                            answerLine.getChildAt(k).setTag(R.id.selected,1);
                        }
                    }

                }else {
                    textView.setText(string.get(i) + "______");
                    textView.setTag(R.id.selected,0);
                }

                 linearLayout1.addView(textView);
                //点击事件
                textView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        // 这个要分两个方法去做
                        if ("______".equals(((TextView) v).getText() + "")) {
                            // 无填好的内容
                            for (int i = 0; i <questionLine.getChildCount(); i++) {

                                // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                                for (int e=1;e<((LinearLayout)questionLine.getChildAt(i)).getChildCount();e++){
                                    if ("2".equals(((LinearLayout)questionLine.getChildAt(i)).getChildAt(e).getTag(R.id.selected) + "")) {
                                        ((LinearLayout)questionLine.getChildAt(i)).getChildAt(e).setBackgroundColor(Color.parseColor("#ffffff" + ""));
                                        ((LinearLayout)questionLine.getChildAt(i)).getChildAt(e).setTag(R.id.selected, 0);

                                        break;
                                    }
                                }

                            }
                            ((TextView) v).setBackgroundColor(Color.parseColor("#3b7830"));
                            // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                            ((TextView) v).setTag(R.id.selected, 2);

                        } else {
                            // 有填好的内容
                            for (int i = 0; i < answerLine.getChildCount(); i++) {

                                if (((TextView) v).getText().toString().trim()
                                        .equals(((TextView) answerLine.getChildAt(i)).getText().toString().trim())) {
                                    if("3".equals(((TextView) answerLine.getChildAt(i)).getTag(R.id.selected)+"")){
                                        Log.i("======selected=====","3");
                                        ((TextView) answerLine.getChildAt(i))
                                                .setBackgroundDrawable(context.getResources().getDrawable(R.drawable.flag_01));
                                        // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                                        ((TextView) answerLine.getChildAt(i)).setTag(R.id.selected, 1);
                                        ((TextView) answerLine.getChildAt(i)).setEnabled(true);
                                        ((TextView) answerLine.getChildAt(i)).setClickable(true);
                                        break;
                                    }


                                }

                            }
                            for (int i = 0; i <questionLine.getChildCount(); i++) {

                                // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                                for (int e=1;e<((LinearLayout)questionLine.getChildAt(i)).getChildCount();e++){
                                    if ("2".equals(((LinearLayout)questionLine.getChildAt(i)).getChildAt(e).getTag(R.id.selected) + "")) {
                                        ((LinearLayout)questionLine.getChildAt(i)).getChildAt(e).setBackgroundColor(Color.parseColor("#ffffff" + ""));
                                        ((LinearLayout)questionLine.getChildAt(i)).getChildAt(e).setTag(R.id.selected, 0);
//
                                        break;
                                    }
                                }

                            }

                            ((TextView) v).setText("_______");
                            ((TextView) v).setBackgroundColor(Color.parseColor("#3b7830"));
                            // tag标记位 0 无数据未选中 1有数据未选-中 2无数据选中 3有数据选中
                            ((TextView) v).setTag(R.id.selected, 2);
//                            ((TextView) v).startAnimation(mAnimation1);
                        }

                        //点击内容的时候遍历出答案是否正确
                        StringBuffer sb = new StringBuffer();
                        ArrayList<String> anser = new ArrayList<String>();
                        for (int i = 0; i < questionLine.getChildCount(); i++) {
                            for (int e=1;e<((LinearLayout)questionLine.getChildAt(i)).getChildCount();e++){
                                if (((LinearLayout)questionLine.getChildAt(i)).getChildAt(e) instanceof AutoResizeTextView) {
                                    String to = ((TextView) ((LinearLayout)questionLine.getChildAt(i)).getChildAt(e)).getText().toString().trim();
                                    sb.append(to);
                                    anser.add(to);
                                }
                            }

                        }
                        list.get(position).setAnwser_xuan(anser);//注：Listview下拉后会清除数据 ，保存到这里（代表选中的），然后判断不为空的时候加载到数据中

                        StringBuilder ssss = new StringBuilder();
                        for (int j = 0; j < list.get(position).getAnwser_true().size(); j++) {
                            ssss.append(list.get(position).getAnwser_true().get(j).trim());
                        }
                        System.out.println("WANXING6020:" + sb);
                        System.out.println("WANXING6020:" + ssss);
                        if (sb.equals("")) {//当没有选择答案的时候
                            list.get(position).setXuan(2);
                        } else if (sb.toString().contains("______")) {//因为空的字符串未"___"，所以这里判断当里面包含这个字符的时候代表未选中
                            list.get(position).setXuan(2);
                        } else if (sb.toString().trim().equals(ssss.toString().trim())) {
                            list.get(position).setXuan(0);//0代表选择正确
                        } else {
                            list.get(position).setXuan(1);
                        }
                    }
                });


            } else {
                TextView textView = new TextView(context);
                if (i == 0) {
                    textView.setText(string.get(i) + ":");
                    textView.setClickable(false);
                } else {
                    textView.setText(string.get(i));
                }
                textView.setTextSize(12);
                textView.setTextColor(Color.parseColor("#3b7830"));
                textView.setLayoutParams(params);
                linearLayout1.addView(textView);
//                questionLine.addView(textView);
            }
        }
        questionLine.addView(linearLayout1);
    }

    /**
     * 答案（6232类型  情景对话）
     */
    private void duihuaYJanswerAdd(final FlowLayout answerLine, String string, ArrayList<String> xuan, final LinearLayout questionLine, final int position) {
        // 设置添加的textvIew的参数
        Log.d("========","duihuaYJanswerAdd");
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        params.setMargins(0, 15, 25, 5);
        TextView textView = new TextView(context);
        textView.setText(string);
        textView.setTextSize(14);
        textView.setPadding(5,5,5,5);
        textView.setGravity(Gravity.LEFT);
        textView.setTag(R.id.selected,1);
        textView.setTextColor(Color.parseColor("#ffffff"));
        // textView.setBackgroundColor(Color.parseColor("#0000ff"));
        textView.setLayoutParams(params);
        setBackgroundResourceWithPadding(textView,context.getResources().getDrawable(R.drawable.flag_01));
        answerLine.addView(textView);
        if (xuan != null && !xuan.equals("")) {
            for (int i = 0; i < xuan.size(); i++) {
                if (string.equals(xuan.get(i))) {
                    setBackgroundResourceWithPadding(textView,context.getResources().getDrawable(R.drawable.flag_04));
                    textView.setTag(R.id.selected,3);
                    textView.setSelected(false);
                }
            }


        }else {
            setBackgroundResourceWithPadding(textView,context.getResources().getDrawable(R.drawable.flag_01));
            textView.setTag(R.id.selected,1);
            textView.setSelected(true);
        }

        textView.setOnClickListener(new View.OnClickListener() {

            boolean isfirst=true;
            @Override
            public void onClick(View v) {
                if("3".equals(v.getTag(R.id.selected)+"")){
                        return;
                }
                isfirst=true;
//                MAlert.alert(v.getTag(R.id.selected)+"");
                for (int i = 0; i < questionLine.getChildCount(); i++) {
                    // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                    for (int m=1;m<((LinearLayout)questionLine.getChildAt(i)).getChildCount();m++){
                        if ("2".equals(((LinearLayout) questionLine.getChildAt(i)).getChildAt(m).getTag(R.id.selected) + "")&&isfirst) {
                            String sss = ((TextView) v).getText().toString().trim();

                            ((AutoResizeTextView)((LinearLayout) questionLine.getChildAt(i)).getChildAt(m)).setText(Html.fromHtml("<u>" + sss + "</u>"));
                            ((AutoResizeTextView)((LinearLayout) questionLine.getChildAt(i)).getChildAt(m)).setTag(R.id.selected,1);
//
                            //点击的时候遍历出答案是否正确
                            StringBuffer sb = new StringBuffer();
                            ArrayList<String> anser = new ArrayList<String>();
                            for (int ii = 0; ii < questionLine.getChildCount(); ii++) {
                                for (int e=1;e<((LinearLayout)questionLine.getChildAt(ii)).getChildCount();e++){
                                    if ((((LinearLayout) questionLine.getChildAt(ii)).getChildAt(e)) instanceof AutoResizeTextView) {

                                        String to = ((TextView)((LinearLayout) questionLine.getChildAt(ii)).getChildAt(e)).getText().toString().trim();
                                       Log.d("====quest====",to);
                                        sb.append(to);
                                        anser.add(to);
                                    }else {

                                    }
                                }

                            }
                            Log.d("====questsize====",anser.size()+"");
                            list.get(position).setAnwser_xuan(anser);//注：Listview下拉后会清除数据 ，保存到这里（代表选中的），然后判断不为空的时候加载到数据中

                            StringBuilder ssss = new StringBuilder();
                            for (int j = 0; j < list.get(position).getAnwser_true().size(); j++) {
                                ssss.append(list.get(position).getAnwser_true().get(j).trim());
                            }
                            System.out.println("UIIHIUHHOIS" + sb);
                            System.out.println("UIIHIUHHOIS" + ssss);
                            if (sb.equals("")) {
                                list.get(position).setXuan(2);//2代表没有输入
                            } else if (sb.toString().trim().equals(ssss.toString().trim())) {
                                list.get(position).setXuan(0);//0代表选择正确
                            } else {
                                list.get(position).setXuan(1);//1代表选择错误
                            }

                            v.setEnabled(false);
                            v.setClickable(false);
                            ((TextView) v).setTag(R.id.selected,3);
                            ((TextView) v).setBackgroundDrawable(context.getResources().getDrawable(R.drawable.flag_04));
                            // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                            ((LinearLayout)questionLine.getChildAt(i)).getChildAt(0).setTag(R.id.selected, 1);

                            for (int j = 0; j < questionLine.getChildCount(); j++) {
                                for (int e=1;e<((LinearLayout)questionLine.getChildAt(j)).getChildCount();e++){
                                    (((LinearLayout) questionLine.getChildAt(j)).getChildAt(e)).setBackgroundColor(Color.parseColor("#ffffff"));
                                }
                            }

                            for (int j = 0; j < questionLine.getChildCount(); j++) {
                                boolean isTiao=false;
                                // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                                for (int e=1;e<((LinearLayout)questionLine.getChildAt(j)).getChildCount();e++){
                                    if ("0".equals((((LinearLayout) questionLine.getChildAt(j)).getChildAt(e)).getTag(R.id.selected) + "")&&isfirst) {
                                        (((LinearLayout) questionLine.getChildAt(j)).getChildAt(e)).setBackgroundColor(Color.parseColor("#3b7830"));
                                            // tag标记位 0 无数据未选中 1有数据未选中 2无数据选中 3有数据选中
                                        (((LinearLayout) questionLine.getChildAt(j)).getChildAt(e)).setTag(R.id.selected, 2);
//                                        (((LinearLayout) questionLine.getChildAt(j)).getChildAt(e)).startAnimation(mAnimation1);
                                        isTiao=true;
                                        isfirst=false;
                                        Log.i("======istiao===","次数+");
                                    }
//                                    else {
//                                        (((LinearLayout) questionLine.getChildAt(j)).getChildAt(e)).getAnimation().cancel();
//                                    }
                                    if(isTiao){
                                        break;
                                    }

                                }
                                if(isTiao){
                                    break;
                                }


                            }
                            break;
                        }

                    }

                }

            }

        });
    }

    /**
     * 内容 (6227类型  完形填空)
     */
    private void wanxingsContentAdd(final TextView questionLine, ArrayList<String> string) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < string.size(); i++) {
            if (string.get(i).contains("_")) {
                sb.append("<a href=\"http://www.baidu.com\">" + " ( " + string.get(i).replace("_", "") + " ) " + "</a>");
            } else {
                sb.append(string.get(i));
            }
        }
        Log.i("===underline===", sb + "");
        Log.i("===underline===", sb.toString());
        questionLine.setText(Html.fromHtml(sb.toString()));
//        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
//                ViewGroup.LayoutParams.WRAP_CONTENT);
//        params.setMargins(0, 5, 0, 5);
//        for (int i = 0; i < string.size(); i++) {
//            if (string.get(i).contains("_")) {
//                TextView textView = new TextView(context);
//                textView.setText(Html.fromHtml("<u>"+"("+string.get(i).replace("_","")+")"+"</u>"));
//                textView.setTextSize(16);
//                textView.setTextColor(Color.parseColor("#3b7830"));
////                textView.setPadding(15, 0, 15, 0);
//                textView.setLayoutParams(params);
//                questionLine.addView(textView);
//            } else {
//                TextView textView = new TextView(context);
//                textView.setText(string.get(i));
//                textView.setTextSize(16);
//                textView.setTextColor(Color.parseColor("#3b7830"));
////                textView.setPadding(15, 0, 15, 0);
//                textView.setLayoutParams(params);
//                questionLine.addView(textView);
//            }
//        }

    }

    public static void setBackgroundResourceWithPadding(View view, Drawable resId) {
        int bottom = view.getPaddingBottom();
        int top = view.getPaddingTop();
        int right = view.getPaddingRight();
        int left = view.getPaddingLeft();
        view.setBackgroundDrawable(resId);
        view.setPadding(left, top, right, bottom);
    }


}
